package com.xmj.web.controller.ms;

import com.xmj.common.annotation.Log;
import com.xmj.common.core.controller.BaseController;
import com.xmj.common.core.domain.AjaxResult;
import com.xmj.common.core.page.TableDataInfo;
import com.xmj.common.enums.BusinessType;
import com.xmj.common.utils.poi.ExcelUtil;
import com.xmj.ms.domain.Barbers;
import com.xmj.ms.service.IBarbersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 员工Controller
 *
 * @author ohh
 * @date 2024-04-21
 */
@RestController
@RequestMapping("/ms/Barbers")
public class BarbersController extends BaseController
{
    @Autowired
    private IBarbersService barbersService;

    /**
     * 查询员工列表
     */
    @PreAuthorize("@ss.hasPermi('ms:Barbers:list')")
    @GetMapping("/list")
    public TableDataInfo list(Barbers barbers)
    {
        startPage();
        List<Barbers> list = barbersService.selectBarbersList(barbers);
        return getDataTable(list);
    }

    /**
     * 导出员工列表
     */
    @PreAuthorize("@ss.hasPermi('ms:Barbers:export')")
    @Log(title = "员工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Barbers barbers)
    {
        List<Barbers> list = barbersService.selectBarbersList(barbers);
        ExcelUtil<Barbers> util = new ExcelUtil<Barbers>(Barbers.class);
        util.exportExcel(response, list, "员工数据");
    }

    /**
     * 获取员工详细信息
     */
    @PreAuthorize("@ss.hasPermi('ms:Barbers:query')")
    @GetMapping(value = "/{barberID}")
    public AjaxResult getInfo(@PathVariable("barberID") Long barberID)
    {
        return success(barbersService.selectBarbersByBarberID(barberID));
    }

    /**
     * 新增员工
     */
    @PreAuthorize("@ss.hasPermi('ms:Barbers:add')")
    @Log(title = "员工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Barbers barbers)
    {
        return toAjax(barbersService.insertBarbers(barbers));
    }

    /**
     * 修改员工
     */
    @PreAuthorize("@ss.hasPermi('ms:Barbers:edit')")
    @Log(title = "员工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Barbers barbers)
    {
        return toAjax(barbersService.updateBarbers(barbers));
    }

    /**
     * 删除员工
     */
    @PreAuthorize("@ss.hasPermi('ms:Barbers:remove')")
    @Log(title = "员工", businessType = BusinessType.DELETE)
	@DeleteMapping("/{barberIDs}")
    public AjaxResult remove(@PathVariable Long[] barberIDs)
    {
        return toAjax(barbersService.deleteBarbersByBarberIDs(barberIDs));
    }
}
